import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import abilitiesConfig from '@/config/default/abilities.json'
import { Abilities } from '@/types/pokemon'

export interface AbilitiesMap {
  [key: string]: Abilities
}

export const useAbilitiesStore = defineStore('abilities', () => {
  const abilitiesMap = ref<AbilitiesMap>({})
  const abilitiesList = computed(() => Object.values(abilitiesMap.value))

  // 初始化能力数据
  const initData = () => {
    abilitiesMap.value = abilitiesConfig as AbilitiesMap
  }

  // 根据类型获取能力数据
  const getAbilityByType = (type: string): Abilities | undefined => {
    return abilitiesMap.value[type]
  }

  // 获取所有能力类型列表
  const getAbilityTypes = computed(() => {
    return Object.keys(abilitiesMap.value)
  })

  return {
    abilitiesMap,
    abilitiesList,
    initData,
    getAbilityByType,
    getAbilityTypes,
  }
})
